.NET Ramblings

My .NET notepad

ASP.NET AJAX Cascading Dropdowns – Method error 500

Another one almost driving me crazy. After about 8 hours of digging around I finally found a post that helped:

http://forums.asp.net/thread/1486888.aspx

The problem I was having, like many others, was this: I was trying to implement two cascading dropdown lists using ASP.NET AJAX (following this AJAX video – scroll down to #3 How Do I: Use the ASP.NET AJAX CascadingDropDown Control Extender?) . Everything worked except the second dropdown wouldn’t be filled with values but with error code: Method error 500.

Following the hints in the post help me nail it down. It seems the beta releases of ASP.NET AJAX have been extremely buggy. Many of the posts I found were from this beta period, which creates nightmares when you’re trying to find a solution to your problem. Great feeling when you finally nails it!

Like the video I used an XML file as data store. This is a very simple and fast implementation for small applications. If you want to use a database instead there are some sites that give some guidelines but unfortunely no one gives the whole story. This and this are the best places to start. Also this one contains lots of good info but i was having problems following along in his discussions.

December 18, 2006 - Posted by | AJAX

6 Comments »

  1. dhdfdjc

    Comment by rere | November 22, 2008 | Reply

  2. Hi, I am doing project in ASP.net using C#. I am instructed not to use auto-post back. I need that if anyone select and particular “system” from the dropdown then the “failure” of that system will appear in next dropdown. It should be the noted that both are coming from database with tables ‘system_types’ and ‘failure_types’.
    I have tried following AJAX code but it generates error.

    I have applied following cascading property.

    For DropDownList1

    For DropDownList2

    After that I have made a class with name “DropDown” and written following code:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using AjaxControlToolkit;
    using System.Data.SqlClient;

    public class dropdown : System.Web.Services.WebService
    {
    [WebMethod]
    public CascadingDropDownNameValue[] getsystem(String knownCategoryValues, String category)
    {

    System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection();
    sqlCon.ConnectionString = “Data Source=.;Initial Catalog=FTS;Integrated Security=True”;
    sqlCon.Open();

    System.Data.SqlClient.SqlDataReader sqlReader;
    System.Data.SqlClient.SqlCommand sqlCmd = new SqlCommand();

    sqlCmd.CommandText = “Select * from system_types”;
    sqlCmd.Connection = sqlCon;
    sqlReader = sqlCmd.ExecuteReader();

    List mysys = new List();

    while (sqlReader.Read())
    {
    String strName = sqlReader[“sys_name”].ToString();
    String strId = sqlReader[“sys_id”].ToString();

    mysys.Add(new CascadingDropDownNameValue(strName, strId));
    }

    sqlReader.Close();
    sqlReader.Dispose();
    sqlCon.Close();
    sqlCon.Dispose();

    return mysys.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] getfailure(String knownCategoryValues, String category)
    {
    System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection();
    sqlCon.ConnectionString = “Data Source=.;Initial Catalog=FTS;Integrated Security=True”;
    sqlCon.Open();

    System.Data.SqlClient.SqlDataReader sqlReader;
    System.Data.SqlClient.SqlCommand sqlCmd = new SqlCommand();

    sqlCmd.CommandText = “Select * from failure_types”;
    sqlCmd.Connection = sqlCon;
    sqlReader = sqlCmd.ExecuteReader();
    StringDictionary kvTeam = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

    Int32 intConfId;

    if (!kvTeam.ContainsKey(“system_types”) || !Int32.TryParse(kvTeam[“system_types”], out intConfId))
    {
    return null;
    }

    sqlCmd.Parameters.AddWithValue(“@confid”, intConfId);

    List myfail = new List();

    while (sqlReader.Read())
    {
    String strTeamName = sqlReader[“failure_name”].ToString();
    String strTeamId = sqlReader[“team_id”].ToString();

    myfail.Add(new CascadingDropDownNameValue(strTeamName, strTeamId));
    }

    sqlReader.Close();
    sqlReader.Dispose();
    sqlCon.Close();
    sqlCon.Dispose();

    return fail.ToArray();
    }

    Next, I have called these two method DropDownList1_SelectedIndexChanged event with following code.

    dropdown dr = new dropdown();
    dr.getfailure(DropDownList1.SelectedValue, DropDownList1.Text);

    When I run it, It give [Method error 500] in both dropdown.
    Please correct me, I have very short time.
    I want that first downdownlist1 should be filled with value from table name “system_types” and dropdownlist2 should filled with value from table with “failure types”.

    Comment by Alok | June 6, 2009 | Reply

  3. hi
    i have the same issue
    just add
    sing AjaxControlToolkit;
    using System.Collections.Specialized;

    [WebService(Namespace = “http://tempuri.org/”)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]

    before the public class dropdown : System.Web.Services.WebService

    Comment by Alaa Barqawi | October 27, 2009 | Reply

  4. Next, I have called these two method DropDownList1_SelectedIndexChanged event with following code.

    dropdown dr = new dropdown();
    dr.getfailure(DropDownList1.SelectedValue, DropDownList1.Text);

    When I run it, It give [Method error 500] in both dropdown.
    Please correct me, I have very short time.
    I want that first downdownlist1 should be filled with value from table name “system_types” and dropdownlist2 should filled with value from table with “failure types”.

    Comment by jayshri | April 4, 2011 | Reply

  5. You can purge files that have changed and allowing online backup reviewss to
    be a little bit more expensive than a limited space one, but scheduling isn’t included. Database StorageThere are three distinct options available for an additional cost of just under 20 dollars per annum.

    Comment by online backup reviews | July 18, 2013 | Reply

  6. I see you don’t monetize your page, don’t
    waste your traffic, you can earn extra cash every month. You can use the best adsense
    alternative for any type of website (they approve all websites), for more info
    simply search in gooogle: boorfe’s tips monetize your website

    Comment by BestJorja | September 5, 2018 | Reply


Leave a comment